package com.lwisniewski.pg.hematometry.pipeline.in;

import gnu.io.CommPortIdentifier;

import java.io.IOException;
import java.io.InputStream;

import javax.sql.rowset.serial.SerialRef;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.lwisniewski.pg.pulsehematometry.serial.facade.SerialPortReaderFacade;


public class PipelineInputMain {
	private final static Logger LOGGER = LoggerFactory.getLogger(PipelineInputMain.class);
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PipelineInput input = new PipelineInput();
		SerialPortReaderFacade facade = input.getSerialFacade();
		
		for(CommPortIdentifier id : facade.getAvailablePortList()) {
			if(id.getName().equals("COM3")) {
				facade.openPort(id);
			}
		}
	//	facade.openPort("COM3");
		InputStream inputStream = facade.getRs232InputStream();
		
		try {
			while(inputStream.available() > 0) {
				LOGGER.info("Reading char: {}", inputStream.read());
			}
		} catch (IOException e) {
			LOGGER.error("Error has occurred in {}.", PipelineInputMain.class);
		}
	}
	

}
